# -*- coding: utf-8 -*-
# @Time    : 2024/8/29 下午11:42
# @Author  : liujun
# @Email   : 2592730854@qq.com
# @File    : source_page.py
# @Software: PyCharm

from selenium.webdriver.common.by import By
from pages.base_page import BasePage
from selenium.webdriver.support.select import Select

class  SourcePage(BasePage):
    """线索"""

    url = "/crm/index.php?m=leads"
    source_pool_btn_locator =(By.CSS_SELECTOR,"body > div.container > div.page-header > ul > li:nth-child(2) > a")  #线索池按钮
    source_add_btn_locator=(By.CSS_SELECTOR,"body > div.container > div.row > div:nth-child(1) > div > a")  #新建线索按钮
    check_box_locator = (By.NAME, "leads_id[]")  #线索勾选框
    source_tool_locator = (By.CSS_SELECTOR, "body > div.container > div.row > div:nth-child(1) > div > div > button")  #线索工具
    action_box_locator = (By.CSS_SELECTOR, "body > div.container > div.row > div:nth-child(1) > ul > li:nth-child(1) > div > a")  #批量操作框
    more_locator = (By.CLASS_NAME, "dropdown-toggle")  # 更多按钮
    source_import_locator = (By.ID, "import_excel")  # 导入线索
    # 点击导入
    import_btn_locator = (By.CSS_SELECTOR,
                          "#dialog-import > form > table > tbody > tr:nth-child(5) > td:nth-child(2) > input.btn.btn-primary")

    batch_delete_locator = (By.ID, "delete")  # 批量删除

    condition_one_select_locator = (By.ID, "field")  # 第一个筛选框
    condition_two_select_locator = (By.ID, "condition")  # 第二个筛选框
    search_locator = (By.ID, "search")  # 搜索框
    search_btn_locator = (By.ID, "dosearch")  # 搜索按钮

    check_locator = (By.LINK_TEXT, "查看")  # 查看
    convert_locator = (By.LINK_TEXT, "转换")  # 转换
    modify_locator = (By.LINK_TEXT, "修改")  # 修改

    next_page_locator = (By.LINK_TEXT, "下一页 »")  # 下一页
    upper_page_locator = (By.LINK_TEXT, "« 上一页")  # 上一页
    first_page_locator = (By.LINK_TEXT, "首页")  # 首页
    jump_page_locator = (By.NAME, "p")  # 跳转多少页
    show_page_locator = (By.ID, "listrows")  # 每页显示多少

    save_custom_locator = (By.CSS_SELECTOR, "#form1 > table > tfoot > tr > td > input:nth-child(1)")  # 客户界面保存
    custom_name_locator=(By.CSS_SELECTOR,"#name")  #转化客户 客户名

    def click_source_add_btn(self):
        """点击新建线索"""
        self.driver.find_element(*self.source_add_btn_locator).click()
    def click_action_box(self):
        """点击批量操作框"""
        self.driver.find_element(*self.action_box_locator).click()
    def click_source_tool(self):
        """点击线索工具"""
        self.driver.find_element(*self.source_tool_locator).click()
    def click_source_import(self):
        """点击导入线索"""
        self.driver.find_element(*self.source_import_locator).click()
    def upload_file(self,file):
       """上传文件"""
       self.driver.find_element(By.NAME, "excel").send_keys(file)

    def click_import_btn(self):
        """点击导入"""
        self.driver.find_element(*self.import_btn_locator).click()


    def click_check_box(self):
        """勾选一条线索"""
        self.driver.find_element(*self.check_box_locator).click()
    def click_more(self):
        """点击更多按钮"""
        self.driver.find_element(*self.more_locator).click()
    def click_source_pool_btn(self):
        """点击线索池"""
        self.driver.find_element(*self.source_pool_btn_locator).click()
    def click_batch_delete(self):
        """点击批量删除"""
        self.driver.find_element(*self.batch_delete_locator).click()
    def select_condition_one(self,choose_one):
        """第一个筛选框"""
        condition_one_select_element = self.driver.find_element(*self.condition_one_select_locator)
        condition_one_select_obj = Select(condition_one_select_element)
        condition_one_select_obj.select_by_visible_text(choose_one)

    def select_condition_two(self,choose_two):
        """第二个筛选框"""
        condition_two_select_element = self.driver.find_element(*self.condition_two_select_locator)
        condition_two_select_obj = Select(condition_two_select_element)
        condition_two_select_obj.select_by_visible_text(choose_two)
    def click_search_btn(self):
        """点击搜索"""
        self.driver.find_element(*self.search_btn_locator).click()

    def input_search_select(self,content):
        """搜索框输入内容"""
        self.driver.find_element(*self.search_locator).send_keys(content)
    def click_check(self):
        """点击查看"""
        self.driver.find_element(*self.check_locator).click()
    def click_convert(self):
        """点击转换"""
        self.driver.find_element(*self.convert_locator).click()
    def click_modify(self):
        """点击修改"""
        self.driver.find_element(*self.modify_locator).click()
    def click_next_page(self):
        """点击下一页"""
        self.driver.find_element(*self.next_page_locator).click()
    def click_upper_page(self):
        """点击上一页"""
        self.driver.find_element(*self.upper_page_locator).click()
    def click_select_jump_page(self,jump_number):
        """点击跳转至 页"""
        jump_page_element = self.driver.find_element(*self.jump_page_locator)
        jump_page_obj = Select(jump_page_element)
        jump_page_obj.select_by_visible_text(jump_number)
    def click_select_show_page(self,show_number):
        """每页显示"""
        show_page_element = self.driver.find_element(*self.show_page_locator)
        show_page_obj = Select(show_page_element)
        show_page_obj.select_by_visible_text(show_number)

    def accept(self):
        """确定弹框"""
        self.driver.switch_to.alert.accept()
    def click_save_custom(self):
        """客户界面保存"""
        self.driver.find_element(*self.save_custom_locator).click()
    def custom_name(self,customer):
        # 转化客户  客户名
        self.driver.find_element(*self.custom_name_locator).clear()
        self.driver.find_element(*self.custom_name_locator).send_keys(customer)

























